import pandas as pd
import os

def generate_enzymes_and_transporters(output_path):
    """
    生成酶频率数据并保存为CSV。
    output_path: 输出文件路径。
    """
    data = [
        ["CYP1A1", 1, 0, 0, 0, 0],
        ["CYP1A2", 1, 0, 0, 0, 0],
        ["CYP2A6", 0.537, 0.015, 0.399, 0.049, 0],
        ["CYP2B6", 0.524, 0.068, 0.323, 0, 0.085],
        ["CYP2C8", 1, 0, 0, 0, 0],
        ["CYP2C9", 0.934, 0.003, 0.063, 0, 0],
        ["CYP2C18", 1, 0, 0, 0, 0],
        ["CYP2C19", 0.396, 0.134, 0.458, 0.012, 0],
        ["CYP2D6", 0.597, 0.003, 0.39, 0, 0.01],
        ["CYP2E1", 1, 0, 0, 0, 0],
        ["CYP2J2", 1, 0, 0, 0, 0],
        ["CYP3A4", 1, 0, 0, 0, 0],
        ["CYP3A5", 0.42, 0.58, 0, 0, 0],
        ["CYP3A7", 0.12, 0.88, 0, 0, 0],
    ]
    columns = ["Enzyme", "EM Freq", "PM Freq", "IM1 Freq", "IM2 Freq", "UM Freq"]
    df = pd.DataFrame(data, columns=columns)
    df.to_csv(output_path, index=False)
    print(f"已保存酶频率数据到: {output_path}")

def generate_enzyme_abundances_and_turnover(output_path):
    """
    生成酶丰度和酶周转速率常数数据并保存为CSV。
    output_path: 输出文件路径。
    """
    data = [
        ["CYP1A1", 1.24, 118, 0, 0, 0, 0, 0, 0, 0, 0, 0.0183, 56],
        ["CYP1A2", 42, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0.0183, 56],
        ["CYP2A6", 18.8, 57, 1.8, 57, 13, 57, 7.7, 57, 0, 0, 0.0267, 56],
        ["CYP2B6", 6.7, 63, 1.4, 85, 5, 105, 0, 0, 7.7, 128, 0.0217, 56],
        ["CYP2C8", 7.7, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0.0301, 56],
        ["CYP2C9", 87.6, 55, 40.5, 88, 76.7, 81, 0, 0, 0, 0, 0.0067, 56],
        ["CYP2C18", 0.4, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0.0267, 56],
        ["CYP2C19", 4.4, 52, 0, 0, 2.85, 52, 7.01, 89, 10.23, 79, 0.0267, 56],
        ["CYP2D6", 10.47, 65, 0, 0, 3.29, 65, 0, 0, 20.25, 65, 0.0099, 56],
        ["CYP2E1", 124, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0.0176, 63],
        ["CYP2J2", 2, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0.0194, 56],
        ["CYP3A4", 120, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0.0193, 68],
        ["CYP3A5", 82.3, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0.0193, 68],
        ["CYP3A7", 14, 71, 0, 0, 0, 0, 0, 0, 0, 0, 0.0193, 68],
    ]
    columns = [
        "Enzyme", "EM Mean", "EM CV(%)", "PM Mean", "PM CV(%)", "IM1 Mean", "IM1 CV(%)", "IM2 Mean", "IM2 CV(%)", "UM Mean", "UM CV(%)", "Turnover Mean (1/h)", "Turnover CV(%)"
    ]
    df = pd.DataFrame(data, columns=columns)
    df.to_csv(output_path, index=False)
    print(f"已保存酶丰度和周转速率数据到: {output_path}")


def generate_transporter_frequencies(output_path):
    """
    生成转运体频率数据并保存为CSV。
    output_path: 输出文件路径。
    """
    data = [
        ["ABCB1 (P-gp/MDR1)", 1, 0, 0, 0],
        ["ABCB11 (BSEP)", 1, 0, 0, 0],
        ["ABCC1 (MRP1)", 1, 0, 0, 0],
        ["ABCC2 (MRP2)", 1, 0, 0, 0],
        ["ABCC3 (MRP3)", 1, 0, 0, 0],
        ["ABCC4 (MRP4)", 1, 0, 0, 0],
        ["ABCC6 (MRP6)", 1, 0, 0, 0],
        ["ABCG2 (BCRP)", 0.44, 0.1, 0.46, 0],
        ["SLC2A1(GLUT1)", 1, 0, 0, 0],
        ["SLC2A2(GLUT2)", 1, 0, 0, 0],
        ["SLC29A1 (ENT1)", 1, 0, 0, 0],
        ["SLC29A2 (ENT2)", 1, 0, 0, 0],
        ["SLC10A1 (NTCP)", 1, 0, 0, 0],
        ["SLC10A2(ASBT/IBAT)", 1, 0, 0, 0],
        ["SLC15A1(PepT1)", 1, 0, 0, 0],
        ["SLC16A1 (MCT1)", 1, 0, 0, 0],
        ["SLC19A2(THTR1)", 1, 0, 0, 0],
        ["SLC19A3(THTR2)", 1, 0, 0, 0],
        ["SLCO1A2(OATP1A2)", 1, 0, 0, 0],
        ["SLCO1B1 (OATP1B1)", 1, 0, 0, 0],
        ["SLCO1B3 (OATP1B3)", 1, 0, 0, 0],
        ["SLCO1C1(OATP1C1)", 1, 0, 0, 0],
        ["SLCO2B1 (OATP2B1)", 1, 0, 0, 0],
        ["SLCO4C1(OATP4C1)", 1, 0, 0, 0],
        ["SLC22A1 (OCT1)", 1, 0, 0, 0],
        ["SLC22A2 (OCT2)", 1, 0, 0, 0],
        ["SLC22A3 (OCT3)", 1, 0, 0, 0],
        ["SLC22A4 (OCTN1)", 1, 0, 0, 0],
        ["SLC22A5 (OCTN2)", 1, 0, 0, 0],
        ["SLC22A6 (OAT1)", 1, 0, 0, 0],
        ["SLC22A7 (OAT2)", 1, 0, 0, 0],
        ["SLC22A8 (OAT3)", 1, 0, 0, 0],
        ["SLC22A9 (OAT7)", 1, 0, 0, 0],
        ["SLC22A11 (OAT4)", 1, 0, 0, 0],
        ["SLC22A12 (URAT1)", 1, 0, 0, 0],
        ["SLC47A1 (MATE1)", 1, 0, 0, 0],
        ["SLC47A2 (MATE2-K)", 1, 0, 0, 0],
        ["SLC51A/B (OST-α/β)", 1, 0, 0, 0],
    ]
    columns = ["Transporter", "ET Freq", "PT Freq", "IT Freq", "UT Freq"]
    df = pd.DataFrame(data, columns=columns)
    df.to_csv(output_path, index=False)
    print(f"已保存转运体频率数据到: {output_path}")

def generate_transporter_abundances_and_turnover(output_path):
    """
    生成转运体绝对丰度、各表型CV和周转速率数据并保存为CSV。
    output_path: 输出文件路径。
    """
    data = [
        ["ABCB1 (P-gp/MDR1)", 0.246, 1, 59, 0, 0, 0, 0, 0, 0, 0, 0.054, 28],
        ["ABCB11 (BSEP)", 1, 1, 131, 0, 0, 0, 0, 0, 0, 0, 1.00E-06, 30],
        ["ABCC2 (MRP2)", 0.59, 1, 88, 0, 0, 0, 0, 0, 0, 0, 1.00E-06, 30],
        ["ABCC3 (MRP3)", 0.239, 1, 65, 0, 0, 0, 0, 0, 0, 0, 1.00E-06, 30],
        ["ABCC4 (MRP4)", 0, 1, 60, 0, 0, 0, 0, 0, 0, 0, 1.00E-06, 30],
        ["ABCC6 (MRP6)", 0.214, 1, 46, 0, 0, 0, 0, 0, 0, 0, 1.00E-06, 30],
        ["ABCG2 (BCRP)", 0.103, 1, 30, 0.37, 30, 0.67, 30, 0, 0, 1.00E-06, 30],
        ["SLC29A1 (ENT1)", 0.0646, 1, 49, 0, 0, 0, 0, 0, 0, 0, 1.00E-06, 30],
        ["SLC29A2 (ENT2)", 0, 1, 60, 0, 0, 0, 0, 0, 0, 0, 1.00E-06, 30],
        ["SLC10A1 (NTCP)", 0.647, 1, 50, 0, 0, 0, 0, 0, 0, 0, 1.00E-06, 30],
        ["SLC16A1 (MCT1)", 0.638, 1, 60, 0, 0, 0, 0, 0, 0, 0, 1.00E-06, 30],
        ["SLCO1B1 (OATP1B1)", 3.1, 0.584, 73, 0.21, 29, 0.4, 51, 0.81, 62, 0.031, 27],
        ["SLCO1B3 (OATP1B3)", 3.08, 1, 89, 0, 0, 0, 0, 0, 0, 0, 1.00E-06, 30],
        ["SLCO2B1 (OATP2B1)", 1.18, 1, 62, 0, 0, 0, 0, 0, 0, 0, 1.00E-06, 30],
        ["SLC22A1 (OCT1)", 1.27, 1, 44, 0, 0, 0, 0, 0, 0, 0, 1.00E-06, 30],
        ["SLC22A7 (OAT2)", 1.25, 1, 75, 0, 0, 0, 0, 0, 0, 0, 1.00E-06, 30],
        ["SLC22A9 (OAT7)", 1.45, 1, 51, 0, 0, 0, 0, 0, 0, 0, 1.00E-06, 30],
        ["SLC47A1 (MATE1)", 0.146, 1, 51, 0, 0, 0, 0, 0, 0, 0, 1.00E-06, 30],
        ["SLC51A/B (OST-α/β)", 0, 1, 60, 0, 0, 0, 0, 0, 0, 0, 1.00E-06, 30],
        ["Sinusoidal Uptake", 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1.00E-06, 30],
        ["Sinusoidal Efflux", 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1.00E-06, 30],
        ["Canalicular Efflux", 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1.00E-06, 30],
    ]
    columns = [
        "Transporter", "ET Mean", "ET CV(%)", "PT Mean", "PT CV(%)", "IT Mean", "IT CV(%)", "UT Mean", "UT CV(%)", "(reserved1)", "(reserved2)", "Turnover Mean (1/h)", "Turnover CV(%)"
    ]
    df = pd.DataFrame(data, columns=columns)
    df.to_csv(output_path, index=False)
    print(f"已保存转运体丰度和周转速率数据到: {output_path}")

def generate_ugt_frequencies(output_path):
    """
    生成UGT酶表型频率数据并保存为CSV。
    output_path: 输出文件路径。
    """
    data = [
        ["UGT1A1", 0.46, 0.1, 0.44, 0],
        ["UGT1A3", 0.738, 0.003, 0.066, 0.193],
        ["UGT1A4", 1, 0, 0, 0],
        ["UGT1A5", 1, 0, 0, 0],
        ["UGT1A6", 1, 0, 0, 0],
        ["UGT1A7", 1, 0, 0, 0],
        ["UGT1A8", 1, 0, 0, 0],
        ["UGT1A9", 0.996, 0.004, 0, 0],
        ["UGT1A10", 1, 0, 0, 0],
        ["UGT2B4", 1, 0, 0, 0],
        ["UGT2B7", 1, 0, 0, 0],
        ["UGT2B10", 1, 0, 0, 0],
        ["UGT2B11", 1, 0, 0, 0],
        ["UGT2B15", 0.21, 0.28, 0.51, 0],
        ["UGT2B17", 0.02, 0.74, 0.24, 0],
        ["UGT2B28", 1, 0, 0, 0],
    ]
    columns = ["Enzyme", "EM Freq", "PM Freq", "IM Freq", "UM Freq"]
    df = pd.DataFrame(data, columns=columns)
    df.to_csv(output_path, index=False)
    print(f"已保存UGT酶频率数据到: {output_path}")


def main():
    base_dir = os.path.dirname(__file__)
    output_path1 = os.path.join(base_dir, "enzyme_frequencies.csv")
    output_path2 = os.path.join(base_dir, "enzyme_abundances_turnover.csv")
    output_path3 = os.path.join(base_dir, "transporter_frequencies.csv")
    output_path4 = os.path.join(base_dir, "transporter_abundances_turnover.csv")
    output_path5 = os.path.join(base_dir, "ugt_frequencies.csv")
    generate_enzymes_and_transporters(output_path1)
    generate_enzyme_abundances_and_turnover(output_path2)
    generate_transporter_frequencies(output_path3)
    generate_transporter_abundances_and_turnover(output_path4)
    generate_ugt_frequencies(output_path5)

if __name__ == "__main__":
    main() 